package cn.mumzone.pos.presenter;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.pos.model.MemberTicketEntity;
import cn.mumzone.pos.model.source.MemberRepository;
import cn.mumzone.pos.presenter.contract.CouponContract;

public class CouponPresenter extends AbsPresenter<CouponContract.View, MemberRepository> implements CouponContract.Presenter {

    @Override
    public void getTicketAllListPage(final String memberId, String viewType, String page, String pageSize,
                                     final boolean isLoadMore) {

        ApiCallBack<MemberTicketEntity> ticketCallback = new ApiCallBack<MemberTicketEntity>() {
            @Override
            public void onSuccess(MemberTicketEntity memberTicketEntity) {
                if (!isLoadMore) {
                    mView.setTicket(memberTicketEntity);
                } else {
                    mView.appendTicket(memberTicketEntity);
                }
                mView.dismissLoading();
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
                mView.dismissLoading();
            }

            @Override
            public void onNetworkError(BaseResponse response) {
                mView.showNetError();
            }
        };
        mRepo.getTicketAllListPage(memberId, viewType, page, pageSize, ticketCallback);
        addSubscrebe(ticketCallback);
    }
}
